package com.idata.model.enums;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @File SelectType.Java
 * @Modify Time      @Author    @Version    @Description
 * ------------      -------    --------    -----------
 * 2023/10/15         yd.j     1.0         None
 */
public enum SelectType {
    PEOPLE_NAME("纠纷对象", 0),
    CARD_ID("身份证号", 0),
    DISPUTE_NUM("纠纷编号", 1),
    DISPUTE_TYPE("纠纷类型", 2),
    DISPUTE_TIME("纠纷时间", 3),
    ;

    private final String name;

    private final int code;


    SelectType(String name, int code) {
        this.name = name;
        this.code = code;
    }

    public static SelectType of(String name) {
        Objects.requireNonNull(name);

        return Stream.of(values())
                .filter(bean -> bean.name.equals(name))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(name + " not exists!"));
    }

    public static SelectType of(int code) {

        return Stream.of(values())
                .filter(bean -> bean.code == code)
                .findAny().
                orElseThrow(() -> new IllegalArgumentException(code + " not exists!"));
    }
}
